package demo;

import java.util.Deque;
import java.util.LinkedList;

public class MyQueue {
    //用一个入栈序列和一个出栈序列就可实现
    Deque<Integer> inStack;
    Deque<Integer> outStack;

    public MyQueue() {
        inStack=new LinkedList<Integer>();
        outStack=new LinkedList<Integer>();
    }

    public void push(int x) {
        //要入队列元素全部放入入栈序列
        inStack.push(x);

    }

    public int pop() {
        //若出栈序列为空，则将入栈栈序列依次搬到出栈序列
        if(outStack.isEmpty()){
            while(!inStack.isEmpty()){
                outStack.push(inStack.pop());
            }
        }
        //返回出栈序列元素
        return outStack.pop();


    }

    public int peek() {
        if(outStack.isEmpty()){
            while(!inStack.isEmpty()){
                outStack.push(inStack.pop());
            }
        }
        //查看出栈序列栈顶元素
        return outStack.peek();

    }

    public boolean empty() {
        //判断两个栈是否为空
        return inStack.isEmpty()&&outStack.isEmpty();

    }


}